package kz.pompei.ifacer.grot.acts;

import java.util.UUID;

import kz.pompei.ifacer.model.widgets.Widget;

public class DeleteAct extends Act {
  private Widget deletedWidget;
  private int deletedFromIndex;
  private final UUID uuid;
  
  public DeleteAct(UUID uuid) {
    this.uuid = uuid;
  }
  
  @Override
  public void apply(GrotStorage grotStorage) {
    deletedFromIndex = grotStorage.getIndexByUuid(uuid);
    deletedWidget = grotStorage.removeByIndex(deletedFromIndex);
  }
  
  @Override
  public void cancel(GrotStorage grotStorage) {
    grotStorage.insert(deletedFromIndex, deletedWidget);
  }
}
